// component/singleSelectPop/singleSelectPop.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    popType: {
      type: String,
      value: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    customArr: {
      type: Array,
      value: []
    },
    popTitle: {
      type: String,
      value: ""
    }
  },


  /**
   * 组件的初始数据
   */
  data: {
    result: null,
    //选择数据源
    dataArr: [],
    type: "",//单选类型
    title: "",//标题
    isScroll: false,
    payTypeArr: [
      {
        value: "月付",
        label: "月付",
      },
      {
        value: "季付",
        label: "季付",
      },
      {
        value: "半年付",
        label: "半年付",
      },
      {
        value: "年付",
        label: "年付",
      }
    ],
    //房屋装修arr:
    houseDecorations: [
      {
        value: "毛坯",
        label: "毛坯",
      },
      {
        value: "简装",
        label: "简装",
      },
      {
        value: "精装",
        label: "精装",
      },
      {
        value: "豪装",
        label: "豪装",
      }
    ],
    //铺源装修情况:
    shopDecorations: [
      {
        value: "特定行业装修",
        label: "特定行业装修",
      },
      {
        value: "毛坯",
        label: "毛坯",
      },
      {
        value: "简装",
        label: "简装",
      },
      {
        value: "精装",
        label: "精装",
      },
      {
        value: "豪装",
        label: "豪装",
      }
    ],
    elevatorArr: [
      {
        value: "有",
        label: "有",
      },
      {
        value: "无",
        label: "无",
      },
    ],
    //房屋楼型arr:
    buildMoldArr: [
      {
        value: "塔楼",
        label: "塔楼",
      },
      {
        value: "板楼",
        label: "板楼",
      },
      {
        value: "板塔结合",
        label: "板塔结合",
      },
    ],
    newRoles: [
      {
        label: "老板",
        value: 1
      },
      {
        label: "员工",
        value: 2
      },
      {
        label: "店长",
        value: 3
      },
      {
        label: "经纪人",
        value: 4
      }
    ],
    houseUseArr: [
      {
        label: "普通住宅",
        value: "普通住宅"
      },
      {
        label: "商业类",
        value: "商业类"
      },
      {
        label: "别墅",
        value: "别墅"
      },
      {
        label: "四合院",
        value: "四合院"
      },
      {
        label: "车位",
        value: "车位"
      },
      {
        label: "其他",
        value: "其他"
      }
    ],
    //主推类型
    mainTypeArr: [
      {
        value: "公寓",
        label: "公寓",
      },
      {
        value: "住宅",
        label: "住宅",
      },
      {
        value: "别墅",
        label: "别墅",
      },
    ],
    //产权年限
    propertyYears: [
      {
        value: "70年",
        label: "70年"
      },
      {
        value: "40年",
        label: "40年"
      }
    ],
    //楼盘状态
    houseStatusArr: [
      {
        value: "在售",
        label: "在售"
      },
      {
        value: "待售",
        label: "待售"
      },
      {
        value: "停售",
        label: "停售"
      },
    ],
    //权属:
    ownershipArr: [
      {
        value: "商品房",
        label: "商品房"
      },
      {
        value: "公房",
        label: "公房"
      },
      {
        value: "经适房",
        label: "经适房"
      },
      {
        value: "其他",
        label: "其他"
      },
    ],
    //楼层
    storeyArr: [
      {
        value: "低楼层",
        label: "低楼层"
      },
      {
        value: "中楼层",
        label: "中楼层"
      },
      {
        value: "高楼层",
        label: "高楼层"
      },
    ],
    lookStatusArr: [
      {
        value: "随时看房",
        label: "随时看房"
      },
      {
        value: "电话预约",
        label: "电话预约"
      },
    ],
    yearsArr: [
      {
        value: 2025,
        label: "2025年"
      },
      {
        value: 2024,
        label: "2024年"
      },
      {
        value: 2023,
        label: "2023年"
      },
      {
        value: 2022,
        label: "2022年"
      },
      {
        value: 2021,
        label: "2021年"
      },
      {
        value: 2020,
        label: "2020年"
      },
      {
        value: 2019,
        label: "2019年"
      },
      {
        value: 2018,
        label: "2018年"
      },
      {
        value: 2017,
        label: "2017年"
      },
      {
        value: 2016,
        label: "2016年"
      },
      {
        value: 2015,
        label: "2015年"
      },
      {
        value: 2014,
        label: "2014年"
      },
      {
        value: 2013,
        label: "2013年"
      },
      {
        value: 2012,
        label: "2012年"
      },
      {
        value: 2011,
        label: "2011年"
      },
      {
        value: 2010,
        label: "2010年"
      },
      {
        value: 2009,
        label: "2009年"
      },
      {
        value: 2008,
        label: "2008年"
      },
      {
        value: 2007,
        label: "2007年"
      },
      {
        value: 2006,
        label: "2006年"
      },
      {
        value: 2005,
        label: "2005年"
      },
      {
        value: 2004,
        label: "2004年"
      },
      {
        value: 2003,
        label: "2003年"
      },
      {
        value: 2002,
        label: "2002年"
      },
      {
        value: 2001,
        label: "2001年"
      },
      {
        value: 2000,
        label: "2000年"
      },
      {
        value: 1999,
        label: "1999年"
      },
      {
        value: 1998,
        label: "1998年"
      },
      {
        value: 1997,
        label: "1997年"
      },
      {
        value: 1996,
        label: "1996年"
      },
      {
        value: 1995,
        label: "1995年"
      },
      {
        value: 1994,
        label: "1994年"
      },
      {
        value: 1993,
        label: "1993年"
      },
      {
        value: 1992,
        label: "1992年"
      },
      {
        value: 1991,
        label: "1991年"
      },
      {
        value: 1990,
        label: "1990年"
      },

    ],
    towardArr: [
      {
        value: "南北",
        label: "南北"
      },
      {
        value: "朝南",
        label: "朝南"
      },
      {
        value: "朝东",
        label: "朝东"
      },
      {
        value: "朝西",
        label: "朝西"
      },
      {
        value: "朝北",
        label: "朝北"
      },
    ],
    bankArr: [
      {
        value: "中国人民银行",
        label: "中国人民银行"
      },
      {
        value: "农业银行",
        label: "农业银行"
      },
      {
        value: "工商银行",
        label: "工商银行"
      },
      {
        value: "建设银行",
        label: "建设银行"
      },
      {
        value: "交通银行",
        label: "交通银行"
      },
      {
        value: "招商银行",
        label: "招商银行"
      },
      {
        value: "邮政储蓄银行",
        label: "邮政储蓄银行"
      },
      {
        value: "兴业银行",
        label: "兴业银行"
      },
      {
        value: "民生银行",
        label: "民生银行"
      },
      {
        value: "中信银行",
        label: "中信银行"
      },
    ],










  },
  observers: {
    'popType': function (newValue) {
      this.setData({
        type: newValue
      })
      this.dataConfig();
    },
    'popTitle': function (newValue) {
      this.setData({
        title: newValue
      })
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.setData({
        type: this.properties.popType
      })
      if (this.properties.customArr.length > 0) {
        this.setData({
          dataArr: this.properties.customArr
        })
      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dataConfig() {
      //取配置数组
      switch (this.data.type) {
        case "decorationStatus":
          this.setData({
            dataArr: this.data.houseDecorations
          })
          break;
        case "decoration":
          this.setData({
            dataArr: this.data.houseDecorations
          })
          break;
        case "toward":
          this.setData({
            dataArr: this.data.towardArr
          })
          break;
        case "towards":
          this.setData({
            dataArr: this.data.towardArr
          })
          break;
        case "years":
          this.setData({
            dataArr: this.data.yearsArr
          })
          break;
        case "payType":
          this.setData({
            dataArr: this.data.payTypeArr
          })
          break;
        case "shopDecoration":
          this.setData({
            dataArr: this.data.shopDecorations
          })
          break;
        case "lookStatus":
          this.setData({
            dataArr: this.data.lookStatusArr
          })
          break;
        case "storey":
          this.setData({
            dataArr: this.data.storeyArr
          })
          break;
        case "floor":
          this.setData({
            dataArr: this.data.storeyArr
          })
          break;
        case "ownership":
          this.setData({
            dataArr: this.data.ownershipArr
          })
          break;
        case "propertyRights":
          this.setData({
            dataArr: this.data.propertyYears
          })
          break;
        case "elevator":
          this.setData({
            dataArr: this.data.elevatorArr
          })
          break;
        case "houseUse":
          this.setData({
            dataArr: this.data.houseUseArr
          })
          break;

        case "propertyYears":
          this.setData({
            dataArr: this.data.propertyYears
          })
          break;
        case "buildMold":
          this.setData({
            dataArr: this.data.buildMoldArr
          })
          break;
        case "saleStatus":
          this.setData({
            dataArr: this.data.houseStatusArr
          })
          break;
        case "mainType":
          this.setData({
            dataArr: this.data.mainTypeArr
          })
          break;
        case "bankName":
          this.setData({
            dataArr: this.data.bankArr
          })
          break;
        case "newRole":
          this.setData({
            dataArr: this.data.newRoles
          })
          break;

        default:
          break;

      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    clickCenterPopupOverlay() {
      this.triggerEvent('popHide', { show: false });
    },
    //关闭弹窗
    popupCancel() {
      this.triggerEvent('popHide', { show: false });
    },
    //确认选择:
    popupTrue() {
      // this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      if (!this.data.isScroll) {
        this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      }
    },
    //最后的value:
    bindChange(e) {
      console.log("JJLog:新组建选中时:" + JSON.stringify(e));
      let index = e.detail.value[0];
      let value = this.data.dataArr[index];
      console.log("JJLog:选择到的值是:" + JSON.stringify(value));
      this.setData({
        result: value
      })
    },
    bindStartAction() {
      this.setData({
        isScroll: true
      })
    },
    bindEndAction() {
      this.setData({
        isScroll: false
      })
    },
  }
})
